
public class RadioPacket implements Comparable<RadioPacket>
{
	public static final int PACKET_TYPE_LENGTH = 3;
	public static final int PACKET_TYPE_OFFSET = 0;
	
	public static final int PACKET_ID_LENGTH = 7; 
	public static final int PACKET_ID_OFFSET = PACKET_TYPE_LENGTH; 

	public static final int PACKET_DATA_LENGTH = 90; 
	public static final int PACKET_DATA_OFFSET = PACKET_ID_LENGTH + PACKET_TYPE_LENGTH;; 


	public static final int DATA_SAMPLE_RATE_LENGTH = 10; 
	public static final int DATA_SAMPLE_RATE_OFFSET = PACKET_DATA_OFFSET; 
	
	public static final int DATA_DELAY_LENGTH = 10; 
	public static final int DATA_DELAY_OFFSET = DATA_SAMPLE_RATE_OFFSET + DATA_SAMPLE_RATE_LENGTH; 
	
	//public static final int PACKET_DATA_OFFSET = PACKET_ID_LENGTH + PACKET_TYPE_LENGTH;; 

	
	private byte[] dataPacket;
	
	public RadioPacket(int length)
	{
		dataPacket = new byte[length];
	}
	public RadioPacket(byte[] bytes)
	{
		dataPacket = bytes;
	}
	private void setDataAt(int start, int length, byte[] dataPart){
		System.arraycopy(dataPart, 0, dataPacket, start, dataPart.length);
	}
	@Override
	public boolean equals(Object obj)
	{
		if(obj instanceof RadioPacket){
			RadioPacket o = (RadioPacket) obj;
			if(getPacketId().equals(o.getPacketId())) return true;
		}
		return false;
	}
	private byte[] getDataAt(int start, int length){
		byte[] returnData = new byte[length];
		System.arraycopy(dataPacket, start, returnData, 0, length);
		return returnData;
	}

	public void setPacketType(byte[] type){
		setDataAt(PACKET_TYPE_OFFSET, PACKET_TYPE_LENGTH, type);
	}
	public void setPacketId(byte[] id){
		setDataAt(PACKET_ID_OFFSET, PACKET_ID_LENGTH, id);
	}
	public void setData(byte[] data){ 
		setDataAt(PACKET_DATA_OFFSET, PACKET_DATA_LENGTH, data);
	}
	public void setDataSampleRate(byte[] sampleRate){
		setDataAt(DATA_SAMPLE_RATE_OFFSET, DATA_SAMPLE_RATE_LENGTH, sampleRate);
	}
	public void setDataDelay(byte[] delay){
		setDataAt(DATA_DELAY_OFFSET, DATA_DELAY_LENGTH, delay);
	}

	public String getPacketType(){
		return new String(getDataAt(PACKET_TYPE_OFFSET, PACKET_TYPE_LENGTH)).trim();
	}
	public String getPacketId(){
		return new String(getDataAt(PACKET_ID_OFFSET, PACKET_ID_LENGTH)).trim();
	}
	public String getData(){
		return new String(getDataAt(PACKET_DATA_OFFSET, PACKET_DATA_LENGTH)).trim();
	}
	public int getDataSampleRate(){
		return new Integer(new String(getDataAt(DATA_SAMPLE_RATE_OFFSET, DATA_SAMPLE_RATE_LENGTH)).trim());
	}
	public int getDataDelay(){
		return new Integer(new String(getDataAt(DATA_DELAY_OFFSET, DATA_DELAY_LENGTH)).trim());
	}

	public byte[] getBytes()
	{
		return dataPacket;
	}
	
	public static void main(
			String[] args)
	{
		RadioPacket p = new RadioPacket(30);
		p.setPacketType("CON".getBytes());
		p.setPacketId("1023".getBytes());
		p.setDataDelay("1000".getBytes());
		p.setDataSampleRate("1000".getBytes());
		System.out.println(p.getDataDelay());
		System.out.println(p.getPacketId());
		System.out.println(p.getPacketType());
		System.out.println();
		System.out.println();
		for(byte b:p.dataPacket){
			System.out.print(b);
		}
	}
	public int compareTo(RadioPacket o)
	{
		return new Integer(getPacketId())-new Integer(o.getPacketId());
	}
}
